# @Remark:我的学员-详情
# ts_students.py模块下功能：我的英文学员， 学员详情

import time
from selenium.webdriver.common.action_chains import ActionChains

from Common.basepage import BasePage
from PageLocators.TS.ts_mystudents_loc import MyStudentsPageLocator as stu_loc
from TestDatas.TsDatas.ts_mystudents_datas import ts_row_link_loc_data
from PageObjects.tools import replace_loc
from Common.dir_config import audio_dir, img_dir


class TsEnglishStudentPage(BasePage):
    """TS班主任工作平台我的学员"""

    def change_module_page(self, nb1_loc=None, nb2_loc=None,
                           attr_name='class', attr_value='parent-active', nb1_name='', nb2_name=''):
        """
        选择模块页面--导航栏
        :param nb1_loc: 一级导航栏模块定位 # navigation bar 导航栏
        :param nb2_loc: 二级导航栏模块定位
        :param attr_name: 属性名
        :param attr_value: 一级导航栏展开的属性值，默认参数class属性值
        :param nb1_name: 一级导航模块名称
        :param nb2_name: 二级导航模块名称
        """
        time.sleep(5)
        attr_values = self.get_element_attribute(nb1_loc, attr_name, "获取导航栏属性值用于判断一级导航是否展开")
        print('attr_values----', attr_values)
        if attr_value in attr_values:
            self.click_element(nb2_loc, "点击AR二级导航-{}".format(nb2_name))
        else:
            self.click_element(nb1_loc, "点击AR一级导航-{}".format(nb1_name))
            time.sleep(1)
            self.click_element(nb2_loc, "点击AR二级导航-{}".format(nb2_name))
        time.sleep(2)

    # TS我的英文学员
    def go_my_stu_nav(self):
        """打开英文课程学员二级导航页面"""
        self.change_module_page(nb1_loc=stu_loc.nav_my_students_state_loc, nb2_loc=stu_loc.nav_english_students_loc,
                                attr_name='style', attr_value='90deg', nb1_name='我的学员', nb2_name='英文课程学员')

    def eng_stu_lst(self):
        """英文课程学员列表数据"""
        self.click_element(stu_loc.search_loc, "英文课程学员-点击搜索")
        time.sleep(10)

    def get_eng_lst_text(self, lst_loc=stu_loc.eng_stu_lst_data_loc, img_doc="获取英文课程学员列表数据"):
        """获取英文课程学员列表数据"""
        try:
            text = self.get_element_text(lst_loc, img_doc)
        except:
            text = ""
        return text

    def eng_stu_detail(self, link_text=ts_row_link_loc_data):
        """英文课程学员详情"""
        row_link_loc = replace_loc(stu_loc.row_link_loc, link_text)
        self.click_element(row_link_loc, "点击英文课程学员-列表数据-英文名【{}】".format(ts_row_link_loc_data), sleep_time=5)
        self.click_element(stu_loc.stu_detail_class_loc, "班级", sleep_time=3)
        self.click_element(stu_loc.eng_having_class_loc, "英文课程学员详情-班级信息-开课中", sleep_time=3)
        eng_having_class_data = self.get_eng_lst_text(stu_loc.class_tab_table_loc, "获取班级信息-开课中-列表数据")
        self.click_element(stu_loc.eng_not_class_loc, "英文课程学员详情-班级信息-未开课", sleep_time=3)
        eng_not_class_data = self.get_eng_lst_text(stu_loc.class_tab_table_loc, "获取班级信息-未开课-列表数据")
        self.click_element(stu_loc.eng_Finished_class_loc, "英文课程学员详情-班级信息-已结课", sleep_time=3)
        eng_finished_class_data = self.get_eng_lst_text(stu_loc.class_tab_table_loc, "获取班级信息-已结课-列表数据")
        self.click_element(stu_loc.stu_detail_order_loc, "英文课程学员详情-订单")
        stu_detail_order_data = self.get_eng_lst_text(stu_loc.order_tab_table_loc, "获取订单信息-列表数据")
        return eng_having_class_data, eng_not_class_data, eng_finished_class_data, stu_detail_order_data

    def more_message(self):
        """学员详情-更多信息"""
        self.click_element(stu_loc.stu_detail_more_loc, "点击学生信息-更多信息", sleep_time=8)
        self.click_element(stu_loc.share_poster_loc, "学员详情-更多信息页-点击分享海报", sleep_time=3)
        self.click_element(stu_loc.backspace_loc, "学员详情-更多信息页-关闭分享海报", sleep_time=3)
        self.click_element(stu_loc.job_completion_loc, "学员详情-更多信息页-点击作业完成情况", sleep_time=3)
        self.click_element(stu_loc.job_cancel_loc, "学员详情-更多信息页-点击关闭作业完成情况")

    def more_order(self):
        """更多信息-下单"""
        pass
